/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.sql.Date;
import java.util.Map;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.MapKey;

/**
 *
 * @author andrea
 */



@Entity
public class Event implements Serializable {
    
    private static final long serialVersionUID = 1L;
    public static final String findPublicEvent = "Event.publicEvent";
    
    /*---------------------primary key-----------------------------------------*/ 
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long eventID;
    
     /*---------------------attribute-----------------------------------------*/
    
    private Date startdate;
    private Date enddate;
    private String addres;
    private Boolean cancelled;
    private Boolean publicEvent;

    
    /*---------------------foreign key-----------------------------------------*/
    @ManyToOne(targetEntity = Location.class)
    private Location location;
    
    @ManyToOne(targetEntity = User.class)
    private User owner;
    
    @ManyToMany(targetEntity = User.class)
    @MapKey
    @JoinColumn
    private Map<String,User> participants;

    
    

    /*---------------------getter & setter-----------------------------------*/
    public String getAddres() {
        return addres;
    }
    public void setAddres(String addres) {
        this.addres = addres;
    }

    public Long getEventID() {
        return eventID;
    }

    public void setEventID(Long eventID) {
        this.eventID = eventID;
    }
    
    public boolean isPublicEvent() {
        return publicEvent;
    }

    public void setPublicEvent(boolean publicEvent) {
        this.publicEvent = publicEvent;
    }
    
    public void setCancelled(boolean cancelled){
     this.cancelled = cancelled;
    }
    
    public boolean isCancelled(){
        return this.cancelled;
    }

    public Date getStartdate() {
        return startdate;
    }

    public void setStartdate(Date startdate) {
        this.startdate = startdate;
    }

    public Date getEnddate() {
        return enddate;
    }

    public void setEnddate(Date enddate) {
        this.enddate = enddate;
    }

    public Location getLocation() {
        return location;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    public User getOwner() {
        return owner;
    }

    public void setOwner(User owner) {
        this.owner = owner;
    }

    public Map<String, User> getParticipants() {
        return participants;
    }

    public void addPArticipant(User newParticipant) {
        this.participants.put(newParticipant.getEmail(), newParticipant);
    }
    
    
    
}
